package io.github.springstudent.web;

import io.github.springstudent.bean.ResponseResult;
import io.github.springstudent.bean.StockInfo;
import io.github.springstudent.bean.StockOperate;
import io.github.springstudent.bean.StockPrice;
import io.github.springstudent.service.StockService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhouning
 * @date 2022/06/25 15:07
 */
@RestController
public class StockController {

    @Resource
    private StockService stockService;

    @GetMapping("/listStockPrice")
    public ResponseResult<List<StockPrice>> listStockPrice() {

        try {
            return ResponseResult.success(stockService.listStockPrice());
        } catch (Exception e) {
            return ResponseResult.fail(e);
        }
    }

    @PostMapping("/updateStockOperate")
    public ResponseResult<Void> updateStockOperate(@RequestBody StockOperate stockOperate) {
        try {
            stockService.updateStockOperate(stockOperate);
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.fail(e);
        }
    }

    @GetMapping("/getStockInfo")
    public ResponseResult<StockInfo> getStockInfo() {
        try {
            return ResponseResult.success(stockService.getStockInfo());
        } catch (Exception e) {
            return ResponseResult.fail(e);
        }
    }

    @PostMapping("/resetStockOperate")
    public ResponseResult<Void> resetStockOperate() {
        try {
            stockService.resetStock();
            return ResponseResult.success();
        } catch (Exception e) {
            return ResponseResult.fail(e);
        }
    }
}
